import { Nodes } from '@knno/dom';
import { Calendar as UICalendar, CalMode, CalendarEventMap } from '../components/calendar/calendar';
import { JSXProps } from '@knno/dom/jsx';
import { AttrCheck, On, isBool, isDate, isStr, jsxBuild } from './utils';

export { UICalendar, CalMode };

interface CalendarProps extends JSXProps<UICalendar>, On<CalendarEventMap, UICalendar> {
	mode?: CalMode;
	min?: Date;
	max?: Date;
	text?: string;
	value?: string;
	range?: boolean;
	disabled?: boolean;
}

const ATTRS: AttrCheck = {
	mode: (v: unknown) => /^(year|month|day)$/.test(v + ''),
	min: isDate,
	max: isDate,
	text: isStr,
	value: isStr,
	range: isBool,
	disabled: isBool,
};

export function Calendar(props: CalendarProps, children: Nodes[]): UICalendar {
	return jsxBuild(new UICalendar(), props, children, ATTRS);
}
